package com.toman.ui.work.device;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.callback.StringCallback;
import com.toman.Adpter.ItemListAdapter;
import com.toman.Adpter.ItemTypeCheckAdapter;
import com.toman.Enum.BaseEnum;
import com.toman.Enum.PermEnum;
import com.toman.Interfaces.NewBaseUrl;
import com.toman.JavaBean.CheckRecordResultDto;
import com.toman.JavaBean.DeviceCheckRecordEntity;
import com.toman.JavaBean.DictionaryDataEntity;
import com.toman.R;
import com.toman.Util.DialogUtils;
import com.toman.Util.IntentUtils;
import com.toman.Util.JsonUtils;
import com.toman.Util.PermissonUtils;
import com.toman.Util.SPUtils;
import com.toman.Util.StringUtils;
import com.toman.Util.ToastUtil;
import com.toman.Util.ViewUtil;
import com.toman.bean.ItemListBean;
import com.toman.bean.ItemTypeBean;
import com.toman.toolbar.ToolBarActivity;
import com.toman.widget.ClearEditText;
import com.toman.widget.MyListView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Request;
import okhttp3.Response;

public class TallyEditActivity extends ToolBarActivity {
    DeviceCheckRecordEntity bean;
    @BindView(R.id.tv_device_dep)
    TextView tvDeviceDep;
    @BindView(R.id.rl_device_dep)
    RelativeLayout rlDeviceDep;
    @BindView(R.id.tv_device)
    TextView tvDevice;
    @BindView(R.id.rl_device)
    RelativeLayout rlDevice;
    @BindView(R.id.tv_tally_name)
    TextView tvTallyName;
    @BindView(R.id.rl_tally_name)
    RelativeLayout rlTallyName;
    @BindView(R.id.tv_tally_time)
    TextView tvTallyTime;
    @BindView(R.id.rl_tally_time)
    RelativeLayout rlTallyTime;
    @BindView(R.id.tv_check_name)
    TextView tvCheckName;
    @BindView(R.id.rl_check_name)
    RelativeLayout rlCheckName;
    @BindView(R.id.tv_check_time)
    TextView tvCheckTime;
    @BindView(R.id.rl_check_time)
    RelativeLayout rlCheckTime;
    @BindView(R.id.tv_shift)
    TextView tvShift;
    @BindView(R.id.rl_shift)
    RelativeLayout rlShift;
    @BindView(R.id.tv_remark_name)
    TextView tvRemarkName;
    @BindView(R.id.et_remark)
    ClearEditText etRemark;
    @BindView(R.id.lv_result)
    MyListView lvResult;
    @BindView(R.id.ll)
    LinearLayout ll;
    public String status;
    ItemListAdapter adapter;
    List<ItemListBean> list = new ArrayList<ItemListBean>();
    List<ItemTypeBean> list1 = new ArrayList<ItemTypeBean>();
    ItemTypeCheckAdapter adapter1;
    List<DictionaryDataEntity> list_item = new ArrayList<DictionaryDataEntity>();
    Map<String, List<DictionaryDataEntity>> map;
    @BindView(R.id.btn_del)
    Button btnDel;
    @BindView(R.id.btn_check)
    Button btnCheck;
    @BindView(R.id.rl_check)
    RelativeLayout rlCheck;
    String problemName = "";
    //    是否点检项目有问题
    boolean isProblem = false;
    boolean isRepair = false;
    @BindView(R.id.tv_shift_title)
    TextView tvShiftTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tally_edit);
        ButterKnife.bind(this);
        initView();
        initToolBar("设备点检详情");
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.toolbar_edit, menu);
        MenuItem menuItem = menu.findItem(R.id.menu_edit);
        if (status.equals("2")) {
            menuItem.setVisible(false);
        }

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.menu_edit:
                        if (item.getTitle().equals("编辑")) {
                            item.setTitle("完成");
                            adapter1.isEdit(true);
                            adapter1.refreshData(list1);
                            ViewUtil.edit(etRemark);
//                            ViewUtil.click(tvShift);
                            ViewUtil.necessary(tvShiftTitle);
                            lvResult.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                                @Override
                                public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                                    checkDialog(position);
                                    return false;
                                }

                            });
                        } else {
                            add();
                            item.setTitle("编辑");
                            ViewUtil.unedit(etRemark);
                            ViewUtil.unclick(tvShift);
                            adapter1.isEdit(false);
                            adapter1.refreshData(list1);

                        }
                        break;
                }
                return false;
            }
        });

        return true;
    }

    private void initView() {
        adapter = new ItemListAdapter(this);
        adapter1 = new ItemTypeCheckAdapter(this);
        adapter1.isEdit(false);

        adapter1.setActionClickListener(new ItemTypeCheckAdapter.ActionClickListener() {
            @Override
            public void onDetailClick(ItemTypeBean bean) {
                message(1, bean);
            }

            @Override
            public void onCheckClick(ItemTypeBean bean) {

            }
        });
        lvResult.setAdapter(adapter1);


        bean = (DeviceCheckRecordEntity) getIntent().getSerializableExtra("bean");
        isRepair = StringUtils.isEmpty(bean.getRepairRecordIds());


        map = (Map<String, List<DictionaryDataEntity>>) getIntent().getSerializableExtra("map");
        ToastUtil.print("map大小" + map.size() + "按钮状态" + bean.getDeviceCheckItems());
        status = getIntent().getStringExtra("status");
//        初始化不可编辑
        ViewUtil.unedit(etRemark);
        ViewUtil.unclick(tvShift);
//        初始化文字
        tvDeviceDep.setText(bean.getDeviceEntity().getDepartmentEntity().getDepartmentName());
        tvDevice.setText(bean.getDeviceEntity().getDeviceName());
        tvShift.setText(bean.getShiftName());
        etRemark.setText(bean.getRemark());
        if (status.equals("0")) {
            rlTallyName.setVisibility(View.GONE);
            rlTallyTime.setVisibility(View.GONE);
            btnCheck.setText("点检");
            btnDel.setVisibility(View.GONE);

            if (!PermissonUtils.contains(this, BaseEnum.TALLY.has(PermEnum.DELETE))) {
                btnDel.setVisibility(View.GONE);
            }
        } else {
            if (!PermissonUtils.contains(this, BaseEnum.TALLY.has(PermEnum.CHECK))) {
                btnCheck.setVisibility(View.GONE);
            }
            if (!PermissonUtils.contains(this, BaseEnum.TALLY.has(PermEnum.DELETE))) {
                btnDel.setVisibility(View.GONE);
            }
            btnCheck.setText("审核");
            try {
                tvTallyName.setText(bean.getCheckUser().getRealName());
                tvTallyTime.setText(bean.getCreateTime());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        if (status.equals("2")) {
            rlCheck.setVisibility(View.GONE);
            tvCheckName.setText(bean.getAuditUser().getRealName());
            tvCheckTime.setText(bean.getAuditTime());
            ViewUtil.done(tvShift);
        } else {
            rlCheckName.setVisibility(View.GONE);
            rlCheckTime.setVisibility(View.GONE);
        }
        if (bean.getDeviceCheckItems() != null) {
            //   String[] name = bean.getDeviceCheckItems().split(";");
            for (int i = 0; i < bean.getCheckResults().size(); i++) {
                ItemTypeBean bean1 = new ItemTypeBean();
                //   String[] item = name[i].split(":");
                CheckRecordResultDto checkRecordResultDto = bean.getCheckResults().get(i);

                DictionaryDataEntity entity = null;
                try {
                    entity = checkRecordResultDto.getDataEntity();
                } catch (Exception e) {
                    e.printStackTrace();
                    break;
                }
                bean1.setRangeInputValue(checkRecordResultDto.getRangeInputValue());
                bean1.setPassIf(checkRecordResultDto.getPassIf());
                bean1.setCheckIf(checkRecordResultDto.getCheckIf());
                bean1.setId(entity.getId() + "");
                bean1.setStatus(entity.getDataStatus());
                bean1.setRemark(entity.getRemark());
                bean1.setName(entity.getDictValue());
                bean1.setNo(entity.getDictLabel());
                bean1.setContent1(entity.getField1());
//
                bean1.setContent2(entity.getField2Name());
                bean1.setType(entity.getField2());
                bean1.setMinNumber(entity.getMinNumber());
                bean1.setMaxNumber(entity.getMaxNumber());
                bean1.setDefaultNumber(entity.getDefaultNumber());
                bean1.setCheck_status(checkRecordResultDto.getPassIf());


                list1.add(bean1);
            }
            adapter1.refreshData(list1);
        }
    }


    private void checkDialog(int position) {
        ItemTypeBean bean = adapter1.getItem(position);
        String msg = "";
        if (bean.getCheckIf().equals("0")) {
            msg = "是否将该点检项目设为不点检";
        } else {
            msg = "是否将该点检项目设为点检";

        }
        DialogUtils.showDialog(this, msg, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (bean.getCheckIf().equals("0")) {
                    bean.setCheckIf("1");
                } else {
                    bean.setCheckIf("0");

                }
                adapter1.refreshData(list1);
            }
        });
    }

    public void shiftDialog() {
        final AlertDialog dialog;
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater factory = LayoutInflater.from(this);
        //把activity_login中的控件定义在View中
        final View textEntryView = factory.inflate(R.layout.dialog_list, null);
        ListView lv = (ListView) textEntryView.findViewById(R.id.lv);
        lv.setAdapter(adapter);

        builder                //对话框的标题
                .setTitle("选择班次")
                //设定显示的View
                .setView(textEntryView)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        //获取用户输入的“用户名”，“密码”


                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create();
        dialog = builder.show();
        shift();
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ItemListBean itemListBean = adapter.getItem(i);

                bean.setShiftId(itemListBean.getID());
                ;
                tvShift.setText(itemListBean.getName());
                dialog.dismiss();
            }
        });

    }

    public void shift() {


        OkHttpUtils
                .get(NewBaseUrl.shift_list_get)
                .params("companyId", mCompanyId)
                .params("departmentId", bean.getDeviceEntity().getDepartmentEntity().getId() + "")
                .params("token", token)
                .params("key", "")
                .params("limit", "100")
                .params("page", "1")
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "班次列表: " + result);

                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        ViewUtil.lagout(code, getApplicationContext());
                        if (code == 0) {
                            list.clear();
                            JSONObject Jpage = jsonObj.getJSONObject("page");
                            JSONArray jsonArray = Jpage.getJSONArray("list");
                            for (int i = 0; i < jsonArray.size(); i++) {
                                ItemListBean bean = new ItemListBean(jsonArray.getJSONObject(i).getString("shiftName"), jsonArray.getJSONObject(i).getString("id"));
                                list.add(bean);
                            }
                            if (list.size() == 0) {
                                ToastUtil.makeText(getApplicationContext(), "暂无数据，请联系管理员添加");
                            }
                            adapter.refreshData(list);

                            adapter.notifyDataSetChanged();

                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public void message(int type, ItemTypeBean bean) {
        final AlertDialog dialog;
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater factory = LayoutInflater.from(this);
        //把activity_login中的控件定义在View中
        View v = factory.inflate(R.layout.dialog_item_type, null);

        TextView content1 = (TextView) v.findViewById(R.id.tv_content1);
        TextView content2 = (TextView) v.findViewById(R.id.tv_content2);
        TextView content3 = (TextView) v.findViewById(R.id.tv_content3);
        TextView content4 = (TextView) v.findViewById(R.id.tv_content4);
        TextView content5 = (TextView) v.findViewById(R.id.tv_content5);
        TextView content6 = (TextView) v.findViewById(R.id.tv_content6);
        TextView tv_max = (TextView) v.findViewById(R.id.tv_max);
        TextView tv_min = (TextView) v.findViewById(R.id.tv_min);
        TextView tv_default = (TextView) v.findViewById(R.id.tv_default);
        RelativeLayout rl3 = (RelativeLayout) v.findViewById(R.id.rl3);
        RelativeLayout rl4 = (RelativeLayout) v.findViewById(R.id.rl4);
        RelativeLayout rl_max = (RelativeLayout) v.findViewById(R.id.rl_max);
        RelativeLayout rl_min = (RelativeLayout) v.findViewById(R.id.rl_min);
        RelativeLayout rl_default = (RelativeLayout) v.findViewById(R.id.rl_default);
        content1.setText(bean.getNo());
        content2.setText(bean.getName());

        content5.setText(bean.getRemark());
        content6.setText(bean.getStatus());
        if (type == 1) {
            content3.setText(bean.getContent1());
            content4.setText(bean.getContent2());
        } else {
            rl3.setVisibility(View.GONE);
            rl4.setVisibility(View.GONE);

        }
        if (bean.getType().equals("2")) {
            rl_max.setVisibility(View.VISIBLE);
            rl_min.setVisibility(View.VISIBLE);
            rl_default.setVisibility(View.VISIBLE);
            tv_max.setText(bean.getMaxNumber());
            tv_min.setText(bean.getMinNumber());
            tv_default.setText(bean.getDefaultNumber());
        }

        builder                //对话框的标题
                .setTitle(bean.getName())
                //设定显示的View
                .setView(v)
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {


                    }
                })
                //对话框的“退出”单击事件
//                .setNegativeButton("退出", new DialogInterface.OnClickListener() {
//                    public void onClick(DialogInterface dialog, int whichButton) {
//                    }
//                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create();
        dialog = builder.show();

    }

    public void deleteDialog(final DeviceCheckRecordEntity bean) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("确定要删除点检？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        delete(bean);
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }

    public void checkDialog(final DeviceCheckRecordEntity bean) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("确认审核当条点检记录？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        check(bean.getId() + "");
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }

    public void tallyDialog(final DeviceCheckRecordEntity bean) {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("确认点检当条点检记录？")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        tally(bean.getId() + "");

//                        check(bean.getId()+"");
                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }

    private void delete(DeviceCheckRecordEntity bean) {


        Map<String, String> map = new HashMap<String, String>();

        map.put("ids", bean.getId() + "");

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(NewBaseUrl.devicecheckrecord_delete + bean.getId())
                .headers("token", token)
                .postJson(str)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "删除点检: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        ViewUtil.lagout(code, getApplicationContext());

                        if (code == 0) {
                            ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));
                            finish();

                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }

    private void check(String ids) {


        Map<String, String> map = new HashMap<String, String>();

        map.put("ids", ids);

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(NewBaseUrl.devicecheckrecord_verify + ids)
                .headers("token", token)
                .postJson(str)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "审核点检: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        ViewUtil.lagout(code, getApplicationContext());

                        if (code == 0) {
                            ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));
                            finish();

                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }

    private void tally(String ids) {


        Map<String, String> map = new HashMap<String, String>();

        map.put("ids", ids);

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(NewBaseUrl.devicecheckrecord_checkrecords + ids)
                .headers("token", token)
                .postJson(str)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "审核点检: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        ViewUtil.lagout(code, getApplicationContext());

                        if (code == 0) {
                            ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));
                            finish();

                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });
    }

    public void add() {
//故障项目状态和id
        StringBuilder names = new StringBuilder();

        if (list1.size() <= 0) {
            ToastUtil.makeText(getApplicationContext(), "无点检项目，请联系管理员添加");
            return;
        }
        for (int i = 0; i < list1.size(); i++) {
            ItemTypeBean bean = list1.get(i);
            if (bean.getType().equals("2")) {
                if (null == bean.getRangeInputValue()) {
                    ToastUtil.makeText(getApplicationContext(), "点检项目不得存在空值");
                    return;
                }
            }

            if (bean.getPassIf().equals("1")) {
                if (names.length() <= 0) {
                    names.append(bean.getName());
                } else {
                    names.append("、").append(bean.getName());
                }
                isProblem = true;
            }
        }
        problemName = names.toString();


        Map<String, Object> map = new HashMap<String, Object>();
        map.put("departmentId", bean.getDeviceEntity().getDepartmentEntity().getId() + "");
        map.put("id", bean.getId() + "");
        map.put("shiftId", bean.getShiftId());
        map.put("remark", etRemark.getText().toString());
        map.put("checkResults", list1);

        String str = JsonUtils.obj2JsonString(map);
        OkHttpUtils
                .post(NewBaseUrl.devicecheckrecord_update)
                .headers("token", token)
                .headers("Content-Type", "application/json")
                .postJson(str)
                .execute(new StringCallback() {
                    @Override
                    public void onResponse(boolean isFromCache, String result, Request request, @Nullable Response response) {
                        Log.i("test", "更新: " + result);
                        JSONObject jsonObj = JSON.parseObject(result);
                        int code = jsonObj.getInteger("code");
                        ViewUtil.lagout(code, getApplicationContext());

                        if (code == 0) {
                            if (isProblem) {
                                if (isRepair) {
                                    problemDialog();
                                } else {
                                    repairDialog();

                                }
                            } else {
                                ToastUtil.makeText(getApplicationContext(), jsonObj.getString("msg"));

                                finish();
                            }


                        } else {
                            ToastUtil.error(getApplicationContext(), jsonObj.getString("msg"));
                        }

                    }
                });

    }

    public void problemDialog() {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("有点检项目不通过，是否跳转生成报修单")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Bundle bundle = new Bundle();
                        bundle.putString("problemName", problemName);
                        bundle.putString("status", "1");
                        bundle.putString("deviceId", bean.getDeviceEntity().getId() + "");
                        bundle.putString("deviceName", tvDevice.getText().toString());
                        bundle.putString("id", bean.getDeviceEntity().getDepartmentEntity().getId() + "");

                        bundle.putString("deviceName", tvDevice.getText().toString());
                        ToastUtil.makeText(getApplicationContext(), "点检成功，跳转至报修单页面");

                        IntentUtils.startActivity(TallyEditActivity.this, DeviceRepairAddActivity.class, bundle);

                        finish();

                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ToastUtil.makeText(getApplicationContext(), "点检成功，未生成报修单");

                        finish();
                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }

    public void repairDialog() {

        //LayoutInflater是用来找layout文件夹下的xml布局文件，并且实例化

        new AlertDialog.Builder(this)
                //对话框的标题
                .setTitle("已经生成过报修单，是否仍要跳转生成报修单")
                //设定显示的View
                //对话框中的“登陆”按钮的点击事件
                .setPositiveButton("确认", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Bundle bundle = new Bundle();
                        bundle.putString("problemName", problemName);
                        bundle.putString("status", "1");
                        bundle.putString("deviceId", bean.getDeviceEntity().getId() + "");
                        bundle.putString("deviceName", tvDevice.getText().toString());
                        bundle.putString("id", bean.getDeviceEntity().getDepartmentEntity().getId() + "");

                        bundle.putString("deviceName", tvDevice.getText().toString());
                        ToastUtil.makeText(getApplicationContext(), "点检成功，跳转至报修单页面");

                        IntentUtils.startActivity(TallyEditActivity.this, DeviceRepairAddActivity.class, bundle);

                        finish();

                    }

                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ToastUtil.makeText(getApplicationContext(), "点检成功，未生成报修单");

                        finish();
                    }
                })
                // 设置dialog是否为模态，false表示模态，true表示非模态
                .setCancelable(true)
                //对话框的创建、显示
                .create().show();

    }

    @OnClick(R.id.tv_shift)
    public void onViewClicked() {

//        shiftDialog();

    }

    @OnClick({R.id.btn_del, R.id.btn_check})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_del:
                deleteDialog(bean);
                break;
            case R.id.btn_check:

                switch (status) {
                    case "0":
                        tallyDialog(bean);
                        break;
                    case "1":
                        checkDialog(bean);
                        break;
                }
                break;
        }
    }


}
